<template>
  <div class="app-container">
    <header class="app-header">
      <h1>RTSP 多画面播放</h1>
      <button @click="addStream" class="add-btn">
        <span class="icon">+</span> 添加画面
      </button>
    </header>

    <div class="stream-grid" v-if="streams.length > 0">
      <StreamPlayer
        v-for="stream in streams"
        :key="stream.id"
        :stream-id="stream.id"
        :initial-url="stream.url"
        @remove="removeStream"
      />
    </div>

    <div v-else class="empty-state">
      <p>暂无画面，点击上方按钮添加</p>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import StreamPlayer from './components/StreamPlayer.vue'

const streams = ref([
  {
    id: 1,
    url: 'rtsp://用户名:密码@IP:端口/Streaming/Channels/102'
  }
])

let nextId = 2

const addStream = () => {
  streams.value.push({
    id: nextId++,
    url: ''
  })
}

const removeStream = (id) => {
  const index = streams.value.findIndex(s => s.id === id)
  if (index !== -1) {
    streams.value.splice(index, 1)
  }
}
</script>

<style scoped>
.app-container {
  max-width: 1920px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 16px 24px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.app-header h1 {
  font-size: 24px;
  font-weight: 500;
  color: #333;
}

.add-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.add-btn .icon {
  font-size: 20px;
  font-weight: bold;
}

.stream-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: 24px;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.empty-state p {
  font-size: 16px;
  color: #999;
}

@media (max-width: 768px) {
  .stream-grid {
    grid-template-columns: 1fr;
  }

  .app-header {
    flex-direction: column;
    gap: 16px;
  }
}
</style>

